package com.ruoyi.controller;


import com.ruoyi.domain.SpaceCollection;
import com.ruoyi.platform.annotation.Log;
import com.ruoyi.platform.core.controller.BaseController;
import com.ruoyi.platform.core.domain.AjaxResult;
import com.ruoyi.platform.core.page.TableDataInfo;
import com.ruoyi.platform.enums.BusinessType;
import com.ruoyi.platform.utils.poi.ExcelUtil;
import com.ruoyi.service.ISpaceCollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 智联空间收藏Controller
 *
 * @author ruoyi
 * @date 2022-12-19
 */
@RestController
@RequestMapping("/admin/collection")
@Api(tags = {"智联空间收藏服务"})
public class SpaceCollectionController extends BaseController {

    @Autowired
    private ISpaceCollectionService spaceCollectionService;

    /**
     * 查询智联空间收藏列表
     */
    @PreAuthorize("@ss.hasPermi('admin:collection:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询智联空间收藏列表", httpMethod = "GET", notes = "查询智联空间收藏列表")
    public TableDataInfo list(SpaceCollection spaceCollection) {
        startPage();
        List<SpaceCollection> list = spaceCollectionService.selectSpaceCollectionList(spaceCollection);
        return getDataTable(list);
    }

    /**
     * 导出智联空间收藏列表
     */
    @PreAuthorize("@ss.hasPermi('admin:collection:export')")
    @Log(title = "智联空间收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出智联空间收藏列表", httpMethod = "POST", notes = "导出智联空间收藏列表")
    public void export(HttpServletResponse response, SpaceCollection spaceCollection) {
        List<SpaceCollection> list = spaceCollectionService.selectSpaceCollectionList(spaceCollection);
        ExcelUtil<SpaceCollection> util = new ExcelUtil<SpaceCollection>(SpaceCollection.class);
        util.exportExcel(response, list, "智联空间收藏数据");
    }

    /**
     * 获取智联空间收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:collection:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取智联空间收藏详细信息", httpMethod = "GET", notes = "获取智联空间收藏详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(spaceCollectionService.selectSpaceCollectionById(id));
    }

    /**
     * 新增智联空间收藏
     */
    @PreAuthorize("@ss.hasPermi('admin:collection:add')")
    @Log(title = "智联空间收藏", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增智联空间收藏", httpMethod = "POST", notes = "新增智联空间收藏")
    public AjaxResult add(@RequestBody SpaceCollection spaceCollection) {
        return toAjax(spaceCollectionService.insertSpaceCollection(spaceCollection));
    }

    /**
     * 修改智联空间收藏
     */
    @PreAuthorize("@ss.hasPermi('admin:collection:edit')")
    @Log(title = "智联空间收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改智联空间收藏", httpMethod = "PUT", notes = "修改智联空间收藏")
    public AjaxResult edit(@RequestBody SpaceCollection spaceCollection) {
        return toAjax(spaceCollectionService.updateSpaceCollection(spaceCollection));
    }

    /**
     * 删除智联空间收藏
     */
    @PreAuthorize("@ss.hasPermi('admin:collection:remove')")
    @Log(title = "智联空间收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除智联空间收藏", httpMethod = "DELETE", notes = "删除智联空间收藏")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(spaceCollectionService.deleteSpaceCollectionByIds(ids));
    }

}
